﻿using System;
using System.Text;
using HslCommunication.BasicFramework;
using HslCommunication.Core;

namespace HslCommunication.Robot.FANUC
{
	/// <summary>
	/// 机器人的姿态数据
	/// </summary>
	// Token: 0x02000036 RID: 54
	public class FanucPose
	{
		/// <summary>
		/// Xyzwpr
		/// </summary>
		// Token: 0x170000DC RID: 220
		// (get) Token: 0x0600046B RID: 1131 RVA: 0x00011C02 File Offset: 0x0000FE02
		// (set) Token: 0x0600046C RID: 1132 RVA: 0x00011C0A File Offset: 0x0000FE0A
		public float[] Xyzwpr { get; set; }

		/// <summary>
		/// Config
		/// </summary>
		// Token: 0x170000DD RID: 221
		// (get) Token: 0x0600046D RID: 1133 RVA: 0x00011C13 File Offset: 0x0000FE13
		// (set) Token: 0x0600046E RID: 1134 RVA: 0x00011C1B File Offset: 0x0000FE1B
		public string[] Config { get; set; }

		/// <summary>
		/// Joint
		/// </summary>
		// Token: 0x170000DE RID: 222
		// (get) Token: 0x0600046F RID: 1135 RVA: 0x00011C24 File Offset: 0x0000FE24
		// (set) Token: 0x06000470 RID: 1136 RVA: 0x00011C2C File Offset: 0x0000FE2C
		public float[] Joint { get; set; }

		/// <summary>
		/// UF
		/// </summary>
		// Token: 0x170000DF RID: 223
		// (get) Token: 0x06000471 RID: 1137 RVA: 0x00011C35 File Offset: 0x0000FE35
		// (set) Token: 0x06000472 RID: 1138 RVA: 0x00011C3D File Offset: 0x0000FE3D
		public short UF { get; set; }

		/// <summary>
		/// UT
		/// </summary>
		// Token: 0x170000E0 RID: 224
		// (get) Token: 0x06000473 RID: 1139 RVA: 0x00011C46 File Offset: 0x0000FE46
		// (set) Token: 0x06000474 RID: 1140 RVA: 0x00011C4E File Offset: 0x0000FE4E
		public short UT { get; set; }

		/// <summary>
		/// ValidC
		/// </summary>
		// Token: 0x170000E1 RID: 225
		// (get) Token: 0x06000475 RID: 1141 RVA: 0x00011C57 File Offset: 0x0000FE57
		// (set) Token: 0x06000476 RID: 1142 RVA: 0x00011C5F File Offset: 0x0000FE5F
		public short ValidC { get; set; }

		/// <summary>
		/// ValidJ
		/// </summary>
		// Token: 0x170000E2 RID: 226
		// (get) Token: 0x06000477 RID: 1143 RVA: 0x00011C68 File Offset: 0x0000FE68
		// (set) Token: 0x06000478 RID: 1144 RVA: 0x00011C70 File Offset: 0x0000FE70
		public short ValidJ { get; set; }

		/// <summary>
		/// 从原始数据解析出当前的姿态数据
		/// </summary>
		/// <param name="byteTransform">字节变化内容</param>
		/// <param name="content">原始的内容</param>
		/// <param name="index">索引位置</param>
		// Token: 0x06000479 RID: 1145 RVA: 0x00011C7C File Offset: 0x0000FE7C
		public void LoadByContent(IByteTransform byteTransform, byte[] content, int index)
		{
			this.Xyzwpr = new float[9];
			for (int i = 0; i < this.Xyzwpr.Length; i++)
			{
				this.Xyzwpr[i] = BitConverter.ToSingle(content, index + 4 * i);
			}
			this.Config = FanucPose.TransConfigStringArray(byteTransform.TransInt16(content, index + 36, 7));
			this.Joint = new float[9];
			for (int j = 0; j < this.Joint.Length; j++)
			{
				this.Joint[j] = BitConverter.ToSingle(content, index + 52 + 4 * j);
			}
			this.ValidC = BitConverter.ToInt16(content, index + 50);
			this.ValidJ = BitConverter.ToInt16(content, index + 88);
			this.UF = BitConverter.ToInt16(content, index + 90);
			this.UT = BitConverter.ToInt16(content, index + 92);
		}

		/// <inheritdoc />
		// Token: 0x0600047A RID: 1146 RVA: 0x00011D60 File Offset: 0x0000FF60
		public override string ToString()
		{
			StringBuilder stringBuilder = new StringBuilder(string.Format("FanucPose UF={0} UT={1}", this.UF, this.UT));
			bool flag = this.ValidC != 0;
			if (flag)
			{
				stringBuilder.Append("\r\nXyzwpr=" + SoftBasic.ArrayFormat<float>(this.Xyzwpr) + "\r\nConfig=" + SoftBasic.ArrayFormat<string>(this.Config));
			}
			bool flag2 = this.ValidJ != 0;
			if (flag2)
			{
				stringBuilder.Append("\r\nJOINT=" + SoftBasic.ArrayFormat<float>(this.Joint));
			}
			return stringBuilder.ToString();
		}

		/// <summary>
		/// 从原始的字节数据创建一个新的姿态数据
		/// </summary>
		/// <param name="byteTransform"></param>
		/// <param name="content">原始的内容</param>
		/// <param name="index">索引位置</param>
		/// <returns>姿态数据</returns>
		// Token: 0x0600047B RID: 1147 RVA: 0x00011E04 File Offset: 0x00010004
		public static FanucPose PraseFrom(IByteTransform byteTransform, byte[] content, int index)
		{
			FanucPose fanucPose = new FanucPose();
			fanucPose.LoadByContent(byteTransform, content, index);
			return fanucPose;
		}

		/// <summary>
		/// 将short类型的config数组转换成string数组类型的config
		/// </summary>
		/// <param name="value">short数组的值</param>
		/// <returns>string数组的值</returns>
		// Token: 0x0600047C RID: 1148 RVA: 0x00011E28 File Offset: 0x00010028
		public static string[] TransConfigStringArray(short[] value)
		{
			return new string[]
			{
				(value[0] != 0) ? "F" : "N",
				(value[1] != 0) ? "L" : "R",
				(value[2] != 0) ? "U" : "D",
				(value[3] != 0) ? "T" : "B",
				value[4].ToString(),
				value[5].ToString(),
				value[6].ToString()
			};
		}
	}
}
